import java.util.concurrent.locks.ReentrantLock;

// Java 可重入锁
public class ReentrantLock_ex {
    public synchronized void add(){
        add();
    }
    public static void main(String[] args) {
        // new ReentrantLock_ex().add(); 栈溢出，因为可以重复加锁
        
    }

    public static void lock_ex(){
        ReentrantLock lock = new ReentrantLock();
        new Thread(()->{
            try{
                // 上锁
                lock.lock();
                System.out.println("上锁");
            }
            finally{
                // 解锁
                lock.unlock();
            }   
        },"A1");
    }
}
